﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using PsychveyApp1.classes;

namespace PsychveyApp1
{

    public partial class MySurvey : System.Web.UI.Page
    {
        static UserAccount ua = new UserAccount();
        static Survey sv = new Survey();
        static ArrayList surveylist = new ArrayList();

        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["PsychAppDBConnectionString"].ConnectionString);
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                lblUsernameMyAccount.Text = (string)(Session["username"]);

                ua = (UserAccount)Session["currentUser"];
                surveylist = DBManager.GetSurveyByUserID(ua.userID);
                dgvMySurvey.DataSource = surveylist;
                dgvMySurvey.DataBind();
                dgvMySurvey.Visible = true;

            }

        }

        public void FillSurveyGrid()
        {

            surveylist = DBManager.GetSurveyByUserID(ua.userID);
            dgvMySurvey.DataSource = surveylist;
            dgvMySurvey.DataBind();
            dgvMySurvey.Visible = true;
        }

        protected void btnProceed_Click(object sender, EventArgs e)
        {
            if (ddlUser.SelectedIndex == 1)
            {

                Response.Redirect("UserAccountHome.aspx");
            }
            else if (ddlUser.SelectedIndex == 2)
            {
                Response.Redirect("Home.aspx");
            }
        }

        protected void ddlUser_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void btnCreateSurvey_Click(object sender, EventArgs e)
        {
            
            Response.Redirect("CreateSurvey.aspx");
        }

        //protected void dgvMySurvey_RowCommand(object sender, GridViewCommandEventArgs e)
        //{
            //string currentCommand = e.CommandName;
            //int currentRowIndex = Int32.Parse(e.CommandArgument.ToString());
            //string surveyID = dgvMySurvey.DataKeys[currentRowIndex].Value;

            //if (e.CommandName == "EditRow")
            //{
                //Response.Redirect("CreateSurvey2.aspx");
            //}

        //}

        protected void dgvMySurvey_SelectedIndexChanged(object sender, EventArgs e)
        {
            //int colIndex = dgvMySurvey.SelectedRow.Cells.G
            
            //int rowIndex = dgvMySurvey.SelectedRow.RowIndex;
            //dgvMySurvey.SelectedIndex.ToString();
            GridViewRow row = dgvMySurvey.SelectedRow;
            //String text = (String)dgvMySurvey.SelectedValue;
            Survey sv1 = new Survey();
            sv1.surveyID = row.Cells[1].Text;
            sv1.title = row.Cells[2].Text;
            sv1.dateCreated = row.Cells[3].Text;
            sv1.dateModified = row.Cells[4].Text;
            sv1.expirationDateOfSurvey = row.Cells[5].Text;
            sv1.typeOfSurvey = row.Cells[6].Text;
            sv1.userID = row.Cells[7].Text;
            sv1.noOfRespondents = row.Cells[8].Text;

            Session["currentSurvey"] = sv1;
            Session["currentPageNumber"] = 1;
            Response.Redirect("InformationSheet.aspx");
            //Response.Redirect("CreateSurvey2.aspx");

           
        }

        protected void AdminLoginShortcut_Click(object sender, EventArgs e)
        {
            Response.Redirect("AdminLogin.aspx");
        }

        protected void LinkButton5_Click(object sender, EventArgs e)
        {
            Response.Redirect("AnswerSurveyHome.aspx");
        }

        protected void LinkButton6_Click(object sender, EventArgs e)
        {
            Response.Redirect("AnalyzeSurveyHome.aspx");
        }
    }
}